﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：王广浩 
    //
    // 文件名：DAL_AreaDistributionDelLog.cs
    // 文件功能描述：删除分配送关系记录
    // 创建标识：王广浩2010-07-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Text;
using HZ.DrugTrade.Model;
using HZ.Common;
using HZ.Data;
using System.Data;
using System.Data.SqlClient;
namespace HZ.DrugTrade.DAL
{
  public  class DAL_AreaDistributionDelLog
    {
        /// <summary>
        /// 获得企业配送更改记录日志
        /// </summary>
        /// <param name="where">列表条件</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pagesize">每页大小</param>
        /// <param name="totalrecord">总页数</param>
        /// <returns></returns>
      public static IList<HZ.DrugTrade.Model.View.AreaDistributionDelLog> GetAreaDistributionDelCompany(HZ.DrugTrade.Model.Query.AreaDistributionDelLog where, int currentPage, int pagesize, out int totalrecord)
        {
            string strwhere = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where,true);
            string sql = string.Format(@"Select * From (Select a.*,TB_Area.AreaName,b.CompanyName As CompanyName_TB,c.CompanyName As CompanyName_PS From 
                                        (Select CompanyID_TB,AreaID,CompanyID_PS,count(1) Num From TB_AreaDistributionDelLog  group By CompanyID_TB,AreaID,CompanyID_PS) a 
                                                        Inner Join TB_company b On a.CompanyID_TB=b.CompanyID 
                                                        Inner Join TB_Company c On a.CompanyID_PS=c.CompanyID
                                                        Inner JOin TB_Area On a.AreaID=TB_Area.AreaID) b Where 1=1 {0} 
", strwhere);
            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(sql, pagesize) { CurrentPage = currentPage };
            DataTable dt = pdes.GetSpecailPage();
            totalrecord = pdes.TotalCount;
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.AreaDistributionDelLog>(dt);
        }
      /// <summary>
      /// 获得企业删除配送关系详细记录
      /// </summary>
      /// <param name="ProcureCatalogID"></param>
      /// <param name="currentPage"></param>
      /// <param name="pagesize"></param>
      /// <param name="totalrecord"></param>
      /// <returns></returns>
      public static IList<HZ.DrugTrade.Model.View.AreaDistributionDelLog> GetAreaDistributionDelLogByWhere(HZ.DrugTrade.Model.Query.AreaDistributionDelLog where, int currentPage, int pagesize, out int totalrecord)
      {
          string strwhere = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where,true);
          

          string sql = string.Format(@"Select * from View_AreaDistributionDelLog Where 1=1 {0} ", strwhere);
          HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(sql, pagesize) { CurrentPage = currentPage };
          DataTable dt = pdes.GetSpecailPage();
          totalrecord = pdes.TotalCount;
          return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.View.AreaDistributionDelLog>(dt);
      }
      public static DataTable GetCompanyDelLog(HZ.DrugTrade.Model.Query.Company where, int currentPage, int pagesize, out int totalrecord)
      {
          string strwhere = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition(where,true);
          string sql = string.Format(@"
                                      
                                     select CompanyID,CompanyName,case Companytype when 0 then '生产企业' when 1 then  '经营企业'  when 2 then '配送企业' End As CompanyType,Num From
                                    (select companyid_ps CompanyIDs,count(1) num from 
                                            (select Areaid,Companyid_tb,companyid_ps ,case when count(1)>0 then 1 else 0 end num  from tb_AreaDistributionDelLog
                                            group by  Areaid,Companyid_tb,companyid_ps) a
                                            group by companyid_ps 
                                            union
                                            select Companyid_tb CompanyIDs,count(1) num from 
                                            (select Areaid,Companyid_tb,companyid_ps ,case when count(1)>0 then 1 else 0 end num  from tb_AreaDistributionDelLog
                                            group by  Areaid,Companyid_tb,companyid_ps 
                                            ) a
                                            group by Companyid_tb
                                    ) a Inner Join TB_Company on a.CompanyIDs=TB_Company.Companyid Where 1=1 {0} 
                                    ", strwhere);
          HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(sql, pagesize) { CurrentPage = currentPage };
          DataTable dt = pdes.GetSpecailPage();
          totalrecord = pdes.TotalCount;
          return dt;
      }
  }
}
